using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FutureOpen.Core.func.sql;
using FutureOpen.Web.Pages;
using FutureOpen.Core;
using FutureOpen.Core.func;
using FutureOpen.Core.func.db;
using System.Text;

public partial class controls_GroupTopics :System.Web.UI.UserControl
{
    public int oid;
    private PageBase pbase;

    protected void Page_Load(object sender, EventArgs e)
    {
        pbase = (PageBase)this.Page;
        pbase.PageInit();

        oid = pbase.orgid;
       
        if (!IsPostBack)
        {
            if (oid > 0)
            {
                AspNetPager1.RecordCount = TopicProvider.GetTopicCountByGroup(oid);
                BindArts(0, 30);
                
            }
            
        }

    }

    static string TITLE_FORMAT = "<a href='GroupArtView.aspx?orgid={0}&artid={1}'>{2}</a>";
    static string USR_FORMAT = "<a href='UsrView.aspx?usrid={0}'>{1}</a>";
     private void BindArts(int start, int end)
    {
        DataSet ds = TopicProvider.GetTopicByGroup(oid, start, end);
        StringBuilder sb = new StringBuilder();
        

         foreach(DataRow dr in ds.Tables[0].Rows)
         {
             string title = string.Format(TITLE_FORMAT, this.oid, dr["topic_id"], dr["topic_title"]);
             string usr = string.Format(USR_FORMAT, dr["usr_id"], dr["usr_name"]);
             sb.Append("<tr>");
             sb.Append("<td class='title' style='height: 21px'>" + title + "</td>");
             sb.Append("<td style='height: 21px'>" + usr + "</td>");
             sb.Append("<td style='height: 21px'>"+dr["topic_reply_count"].ToString()+"</td>");
             sb.Append("<td style='width: 132px; height: 21px;'>" + dr["topic_last_modify_time"].ToString() +"</td>");
             sb.Append("</tr>");
         }
         ltTopics.Text = sb.ToString();	        
    }

    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        BindArts(30 * (e.NewPageIndex - 1), 30);
    }    
}

